var chart;
function column_percentage(labelPercent, percentResolve, percentAll, machine_name){
	$(document).ready(function() {
	   chart = new Highcharts.Chart({
		  chart: {
			 renderTo: 'column_percentage_container',
			 defaultSeriesType: 'column'
		  },
		  title: {
			 text: 'Pourcentage de résolution des anomalies pour le ' + machine_name
		  },
		  xAxis: {
			 categories: editCategory(labelPercent)
		  },
		  yAxis: {
			 min: 0,
			 title: {
				text: 'Taux de résolution'
			 }
		  },
		  tooltip: {
			 formatter: function() {
				return ''+
					this.series.name +': '+ this.y +' ('+ Math.round(this.percentage) +'%)';
			 }
		  },
		  plotOptions: {
			 column: {
				stacking: 'percent'
			 }
		  },
		   series: [{
			 name: 'Non Résolu',
			 data : calculAll(labelPercent, percentResolve, percentAll)
		  }, {
			 name: 'Résolu',
			 data: calculNotResolved(labelPercent, percentResolve)
		  }]
	   });
	});
}

function calculAll(labelPercent, percentResolve, percentAll) {
	var data = [];
	for (var i = 0; i < labelPercent.length; i++) {
		value = percentAll[labelPercent[i]] - percentResolve[labelPercent[i]];
		data.push(value);
	}
	return data;
}

function calculNotResolved(labelPercent, percentResolve) {
	var data = [];
	for (var i = 0; i < labelPercent.length; i++) {
			value = percentResolve[labelPercent[i]];
			data.push(value);
	}
	return data;
}


function editCategory(labelPercent){
	var data = [];
	for (var i = 0; i < labelPercent.length; i++) {
		data.push(labelPercent[i]);
	}
	return data;
}
